{% extends 'base.html' %}
{% block head %}
	<link href="{{ path }}js/plugins/msgGrowl/css/msgGrowl.css" rel="stylesheet">
    <link href="{{ path }}js/plugins/msgAlert/css/msgAlert.css" rel="stylesheet">
	<link href="{{ path }}js/plugins/lightbox/themes/evolution-dark/jquery.lightbox.css" rel="stylesheet">  
    <link href="{{ path }}js/plugins/timepicker/jquery.ui.timepicker.css" rel="stylesheet"> 
	<link href="{{ path }}js/plugins/colorpicker/css/colorpicker.css" rel="stylesheet">
    <link href="{{ path }}js/plugins/datatables/DT_bootstrap.css" rel="stylesheet">
	<link href="{{ path }}js/plugins/responsive-tables/responsive-tables.css" rel="stylesheet"> 
    
	<script src="{{ path }}js/plugins/msgGrowl/js/msgGrowl.js"></script>
	<script src="{{ path }}js/plugins/msgAlert/js/msgAlert.js"></script>
    <script src="{{ path }}js/plugins/timepicker/jquery.ui.timepicker.min.js"></script>
    <script src="{{ path }}js/plugins/colorpicker/js/bootstrap-colorpicker.js"></script>
    <script src="{{ path }}js/plugins/lightbox/jquery.lightbox.js"></script>
    <script src="{{ path }}js/demos/demo.ui-elements.js"></script>

	
    <script src="{{ path }}js/demos/demo.tables.js"></script>
    <script src="{{ path }}js/plugins/datatables/jquery.dataTables.js"></script>

    <script src="{{ path }}js/jquery.numeric.js"></script>
    {{ path2 }}    
{% endblock %}

{% block jquery %}

    $( 'form' ).submit(function() {
    	if($('#contrasena-actual').attr('value') != ""){
            if($('#contrasena-nueva').attr('value') == $('#re-contrasena').attr('value')){
                return true;
            }
            else{
                alert("Las contraseñas no coinciden.");
                return false;
            }
		}
        else{
        }
    });

      
     function registrarSede(sede_id){
        $.ajax({
            url: "/configuracion/sedes/nuevo/",
            type: "POST",
            data : {sede_id:sede_id,
                    csrfmiddlewaretoken : $('#csrf_token >div >input').attr("value")
                     },
            dataType: "html",
            success: function(datos) {
                $('#nuevo-sede').html(datos);
            }
        });
    }

    $("#btn-sede").click(function() {
        registrarSede(0);
    });

    $( $(".acc_sede[id^='sede']") ).click(function() {
            sede_id = $(this).attr('value');
            registrarSede(sede_id);
    });



    function registrarCategoria(categoria_id){
        $.ajax({
            url: "/configuracion/categorias/nuevo/",
            type: "POST",
            data : {categoria_id:categoria_id,
                    csrfmiddlewaretoken : $('#csrf_token >div >input').attr("value")
                     },
            dataType: "html",
            success: function(datos) {
                $('#nuevo-categoria').html(datos);
            }
        });
    }

    $("#btn-categoria").click(function() {
        registrarCategoria(0);
    });

    $( $(".acc_cat[id^='cat']") ).click(function() {
            categoria_id = $(this).attr('value');
            registrarCategoria(categoria_id);
    });



    function registrarUnidad(unidad_id){
        $.ajax({
            url: "/configuracion/unidades/nuevo/",
            type: "POST",
            data : {unidad_id:unidad_id,
                    csrfmiddlewaretoken : $('#csrf_token >div >input').attr("value")
                     },
            dataType: "html",
            success: function(datos) {
                $('#nuevo-unidad').html(datos);
            }
        });
    }

    $("#btn-unidad").click(function() {
        registrarUnidad(0);
    });

    $( $(".acc_unid[id^='unid']") ).click(function() {
            unidad_id = $(this).attr('value');
            registrarUnidad(unidad_id);
    });


    function registrarIva(iva_id){
        $.ajax({
            url: "/configuracion/iva/nuevo/",
            type: "POST",
            data : {iva_id:iva_id,
                    csrfmiddlewaretoken : $('#csrf_token >div >input').attr("value")
                     },
            dataType: "html",
            success: function(datos) {
                $('#nuevo-iva').html(datos);
            }
        });
    }

    $("#btn-iva").click(function() {
        registrarIva(0);
    });

    $( $(".acc_iva[id^='iva']") ).click(function() {
            iva_id = $(this).attr('value');
            registrarIva(iva_id);
    });


{% endblock %}
	
{% block ruta %}
		
{% endblock %}

{% block contenido %}
    <div class="span6">
    	<div id="horizontal" class="widget widget-form">
            <div class="widget-header">	      				
                <h3>
                    <i class="icon-pencil"></i>
                    Configuración de empresa
                </h3>
            </div> <!-- /widget-header -->
            
            <div class="widget-content">
                
				<form id="form-institucion" class="form-horizontal" action="/configuracion/guardar/" method="post" enctype="multipart/form-data">
			    {% csrf_token %}
    		    <fieldset>
                    <div class="control-group">
                        <label class="control-label" for="input01">Nit</label>
                        <div class="controls">
                        	<input type="text" class="input-large" name="nit" id="nit" required="required" value="{{ configuracion.nit }}"/>
                        </div>
					</div>
                    <div class="control-group">
                        <label class="control-label" for="input01">Nombre</label>
                        <div class="controls">
                        	<input type="text" class="input-large" name="nombre" id="nombre" required="required" value="{{ configuracion.nombre }}"/>
                        </div>
					</div>
                    <div class="control-group">
                        <label class="control-label" for="input01">Logo</label>
                        <div class="controls">
                            <input type="file" id="foto" name="foto" class="input-file" accept="image/gif,image/jpeg">
                        </div>
					</div>
                    <div class="control-group">
                        <label class="control-label" for="input01">Dirección</label>
                        <div class="controls">
                        	<input type="text" class="input-medium" name="direccion" id="direccion"required="required" value="{{ configuracion.direccion }}"/>
                        </div>
					</div>
                    <div class="control-group">
                        <label class="control-label" for="input01">Teléfono</label>
                        <div class="controls">
                        	<input type="text" class="input-medium" name="telefono" id="telefono" value="{{ configuracion.telefono }}"/>
                        </div>
					</div>

                    <div class="control-group">
                        <label class="control-label" for="input01">Fax:</label>
                        <div class="controls">
                        	<input type="text" class="input-medium" name="fax" id="fax" value="{{ configuracion.fax }}"/>
                        </div>
					</div>
                    
                    <div class="control-group">
                        <label class="control-label" for="input01">Web</label>
                        <div class="controls">
                        	<input type="url" class="input-large" name="web" id="web" required="required" value="{{ configuracion.web }}"/>
                        </div>
					</div>
                    
                    <div class="control-group">
                        <label class="control-label" for="input01">Email</label>
                        <div class="controls">
                        	<input type="email" class="input-large" name="email" id="email" required="required" value="{{ configuracion.email }}"/>
                        </div>
					</div>
                    <div class="control-group">
                        <label class="control-label" for="input01">Fecha de renovación Hosting</label>
                        <div class="controls">
							<label for="input01">{{ configuracion.renovacion_hosting|default_if_none:"" }}</label>
                        	
                        </div>
					</div>
                    <div class="control-group">
                        <label class="control-label" for="input01">Contraseña actual:</label>
                        <div class="controls">
                        	<input type="password" class="input-large" name="contrasena-actual" id="contrasena-actual"/>
                        </div>
					</div>
                    
                    <div class="control-group">
                        <label class="control-label" for="input01">Nueva contraseña:</label>
                        <div class="controls">
                        	<input type="password" class="input-large" name="contrasena-nueva" id="contrasena-nueva"/>
                        </div>
					</div>
                    
                    <div class="control-group">
                        <label class="control-label" for="input01">Confirmar contraseña:</label>
                        <div class="controls">
                        	<input type="password" class="input-large" name="re-contrasena" id="re-contrasena"/>
                        </div>
					</div>
                    
                    <!--
                    {% if texto %}
                        <div class="alert alert-block">
                          <a class="close" data-dismiss="alert" href="#">&times;</a>
                          {{ texto }}
                        </div>
					{% endif %}
                    -->
            		
                    <div class="form-actions">
                        <button type="submit" class="btn btn-primary btn-large">Guardar</button>
                  	</div>
	            	</fieldset>
          		</form>	
                </div> <!-- /.widget-content -->	
				</div> <!-- /.horizontal -->

                <!--
                <div id="horizontal" class="widget widget-form">
                        <div class="widget-header">                     
                            <h3>
                                <i class="icon-pencil"></i>
                                Iva
                            </h3>
                        </div> <!-- /widget-header -->
                <!--
                        <div class="widget-content">
                            <form action="/configuracion/iva/borrar/" method="post">
                            {% csrf_token %}
                                <table class="table table-bordered table-striped table-highlight">
                                    <thead>
                                        <tr>
                                            <th width="5%"></th>
                                            <th width="60%">Nombre</th>
                                            <th width="30%">Valor</th>
                                             <th width="5%" align="center">Editar</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        {% for iva in Iva %}
                                        <tr>
                                            <td><input type="checkbox" id="chk_{{iva.id}}" name="chk_{{iva.id}}" value="false"/></td>
                                            <td>{{ iva.nombre }}</td>
                                            <td>{{ iva.valor }}</td>
                                            <td class="table_center" ><a href="#myModalI" id="unid_{{ iva.id }}" value="{{ iva.id }}" data-toggle="modal" class="acc_iva"><img src="{{ path }}images/24x24/edit.png" /></a></td>
                                        </tr>
                                        {% endfor %}
                                    </tbody>
                                </table>
                                
                                <table width="100%" class="form-actions">
                                    <tr><td width="50%" style="text-align:center"><button type="submit" class="btn btn-medium">Borrar Iva</button></td>
                                    <td width="50%" style="text-align:center"><a href="#myModalI" id="btn-iva" data-toggle="modal" class="btn btn-primary btn-medium">Nuevo Iva</a></td></tr>
                                </table>
                            </form>
                        </div> <!-- /. widget-content -->
                    <!-- /div>  <!-- horizontal -->
			</div> <!-- /.span6 -->
            
            
            <div class="span6">
                <div id="horizontal" class="widget widget-form">
                    <div class="widget-header">	      				
                        <h3>
                            <i class="icon-pencil"></i>
                            Sedes
                        </h3>
                    </div> <!-- /widget-header -->
                    
                    <div class="widget-content">
                    	<form action="/configuracion/sedes/borrar/" method="post">
                        {% csrf_token %}
                        <table class="table table-bordered table-striped table-highlight">
                            <thead>
                                <tr>
                                	<th width="5%"></th>
                                    <th width="35%">Nombre</th>
                                    <th width="20%">Dirección</th>
                                    <th width="15%">Teléfono</th>
                                    <th width="20%">Email</th>
                                    <th width="5%" align="center">Editar</th>
                                </tr>
                            </thead>
                            <tbody>
                                {% for sede in Sedes %}
                                <tr>
                                    <td><input type="checkbox" id="chk_{{sede.id}}" name="chk_{{sede.id}}" value="false"/></td>
                                    <td>{{ sede.nombre }}</td>
                                    <td>{{ sede.direccion|default_if_none:"" }}</td>
                                    <td>{{ sede.telefono|default_if_none:"" }}</td>
                                    <td>{{ sede.email|default_if_none:"" }}</td>
                                    <td class="table_center" ><a href="#myModalS" id="sede_{{ sede.id }}" value="{{ sede.id }}" data-toggle="modal" class="acc_sede"><img src="{{ path }}images/24x24/edit.png" /></a></td>
                                </tr>
                                {% endfor %}
                            </tbody>
                        </table>
						<table width="100%" class="form-actions">
                        	<tr><td width="50%" style="text-align:center"><button type="submit" class="btn btn-medium">Borrar Sede</button></td>
	                        <td width="50%" style="text-align:center"><a href="#myModalS" id="btn-sede" data-toggle="modal" class="btn btn-primary btn-medium">Nueva Sede</a></td></tr>
    	                </table>        
         
                        </form>
                	</div> <!-- /.widget-content -->	
				</div> <!-- /.horizontal -->
			</div> <!-- /.span6 -->
            
            
            <div class="span6">
                <div id="horizontal" class="widget widget-form">
                    <div class="widget-header">	      				
                        <h3>
                            <i class="icon-pencil"></i>
                            Categorias
                        </h3>
                    </div> <!-- /widget-header -->
                    
                    <div class="widget-content">
                    	<form action="/configuracion/categorias/borrar/" method="post">
                        {% csrf_token %}
                        <table class="table table-bordered table-striped table-highlight">
                            <thead>
                                <tr>
                                	<th width="5%"></th>
                                    <th width="45%">Nombre</th>
                                    <th width="15%">Abreviatura</th>
                                    <th width="15%">Sismed</th>
                                    <th width="15%">Dias Ven.</th>
                                     <th width="5%" align="center">Editar</th>
                                </tr>
                            </thead>
                            <tbody>
                                {% for categoria in Categorias %}
                                <tr>
                                    <td><input type="checkbox" id="chk_{{categoria.id}}" name="chk_{{categoria.id}}" value="false"/></td>
                                    <td>{{ categoria.nombre }}</td>
                                    <td>{{ categoria.abrev }}</td>
                                    <td>{% if categoria.sismed %}<img src="{{ path }}img/validate/valid.png"/>{% else %}<img src="{{ path }}img/validate/error.png" />{% endif %}</td>
                                    <td>{{ categoria.dias_vencimiento }}</td>
                                    <td class="table_center" ><a href="#myModalC" id="cat_{{ categoria.id }}" value="{{ categoria.id }}" data-toggle="modal" class="acc_cat"><img src="{{ path }}images/24x24/edit.png" /></a></td>
                                </tr>
                                {% endfor %}
                            </tbody>
                        </table>
						<table width="100%" class="form-actions">
                        	<tr><td width="50%" style="text-align:center"><button type="submit" class="btn btn-medium">Borrar Categoria</button></td>
	                        <td width="50%" style="text-align:center"><a href="#myModalC" id="btn-categoria" data-toggle="modal" class="btn btn-primary btn-medium">Nueva Categoria</a></td></tr>
    	                </table>        
         
                        </form>
                	</div> <!-- /.widget-content -->	
				</div> <!-- /.horizontal -->
			</div> <!-- /.span6 -->
            
            <div class="span6">
            		<div id="horizontal" class="widget widget-form">
                        <div class="widget-header">	      				
                            <h3>
                                <i class="icon-pencil"></i>
                                Unidades
                            </h3>
                        </div> <!-- /widget-header -->
                        
                        <div class="widget-content">
                        	<form action="/configuracion/unidades/borrar/" method="post">
							{% csrf_token %}
                		    	<table class="table table-bordered table-striped table-highlight">
                                	<thead>
                                        <tr>
                                        	<th width="5%"></th>
                                            <th width="60%">Nombre</th>
                                            <th width="30%">Abreviatura</th>
                                             <th width="5%" align="center">Editar</th>
                                        </tr>
									</thead>
                                    <tbody>
                                        {% for unidad in Unidades %}
                                        <tr>
                                        	<td><input type="checkbox" id="chk_{{unidad.id}}" name="chk_{{unidad.id}}" value="false"/></td>
                                            <td>{{ unidad.nombre }}</td>
                                            <td>{{ unidad.abrev }}</td>
                                            <td class="table_center" ><a href="#myModalU" id="unid_{{ unidad.id }}" value="{{ unidad.id }}" data-toggle="modal" class="acc_unid"><img src="{{ path }}images/24x24/edit.png" /></a></td>
                                        </tr>
                                        {% endfor %}
									</tbody>
                                </table>
                                
                                <table width="100%" class="form-actions">
                                    <tr><td width="50%" style="text-align:center"><button type="submit" class="btn btn-medium">Borrar Unidad</button></td>
                                    <td width="50%" style="text-align:center"><a href="#myModalU" id="btn-unidad" data-toggle="modal" class="btn btn-primary btn-medium">Nueva Unidad</a></td></tr>
                                </table>
							</form>
                        </div> <!-- /. widget-content -->
					</div>	<!-- horizontal -->
			</div> <!-- /. span6 -->




	<div class="modal fade hide" id="myModalS">
		<form id="form-sedes" class="form-horizontal" action="/configuracion/sedes/" method="post">
              {% csrf_token %}
              <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal">&times;</button>
                    <h3>Nueva Sede</h3>
              </div>
              <div class="modal-body" id="nuevo-sede">
                    
                    
              </div>
              <div class="modal-footer">
                <a href="#" class="btn btn-medium" data-dismiss="modal">Cerrar</a>
                <button type="submit" class="btn btn-primary btn-medium">Guardar</button>
              </div>
          </form>
    </div>




    <div class="modal fade hide" id="myModalC">
		<form id="form-categorias" class="form-horizontal" action="/configuracion/categorias/" method="post">
            {% csrf_token %}
              <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal">&times;</button>
                    <h3>Nueva Categoría</h3>
              </div>
              <div class="modal-body" id="nuevo-categoria">
                    
                    
              </div>
              <div class="modal-footer">
                <a href="#" class="btn btn-medium" data-dismiss="modal">Cerrar</a>
                <button type="submit" class="btn btn-primary btn-medium">Guardar</button>
              </div>
          </form>
    </div>
    
    
    
	<div class="modal fade hide" id="myModalU">
		<form id="form-unidades" class="form-horizontal" action="/configuracion/unidades/" method="post">
            {% csrf_token %}
              <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal">&times;</button>
                    <h3>Nueva Unidad</h3>
              </div>
              <div class="modal-body" id="nuevo-unidad">
                    
                    
              </div>
              <div class="modal-footer">
                <a href="#" class="btn btn-medium" data-dismiss="modal">Cerrar</a>
                <button type="submit" class="btn btn-primary btn-medium">Guardar</button>
              </div>
		</form>
	</div>


    <div class="modal fade hide" id="myModalI">
        <form id="form-iva" class="form-horizontal" action="/configuracion/iva/" method="post">
            {% csrf_token %}
              <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal">&times;</button>
                    <h3>Nuevo Iva</h3>
              </div>
              <div class="modal-body" id="nuevo-iva">
                    
                    
              </div>
              <div class="modal-footer">
                <a href="#" class="btn btn-medium" data-dismiss="modal">Cerrar</a>
                <button type="submit" class="btn btn-primary btn-medium">Guardar</button>
              </div>
        </form>
    </div>

{% endblock %}